//
//  ConFirmPayView.m
//  WBBaseProject
//
//  Created by xiaozhi on 2018/4/16.
//  Copyright © 2018年 吴斌. All rights reserved.
//

#import "ConFirmPayView.h"
#import "BankTableViewCell.h"

@implementation ConFirmPayView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
//- (instancetype)initWithCoder:(NSCoder *)aDecoder
//{
//    if (self = [super initWithCoder:aDecoder]) {
//
//        self.bankList.dataSource = self;
//        self.bankList.delegate = self;
//
//        [self.bankList registerNib:[UINib nibWithNibName:@"BankTableViewCell" bundle:nil] forCellReuseIdentifier:@"BankTableViewCell"];
//    }
//    return self;
//}
- (void)setBankData:(NSArray *)bankData
{
    
    self.banklist.bankdata = bankData;
}
- (void)awakeFromNib
{
    [super awakeFromNib];
    
    self.banklist = [[NSBundle mainBundle]loadNibNamed:@"BankListView" owner:nil options:nil].firstObject;
    self.banklist.headerView.hidden = YES;
    [self.banklist.bankTable mas_updateConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(0);
    }];
    WB_WEAKSELF;
    self.banklist.chooseBank = ^(NSDictionary *dic) {
        
        
        [weakSelf.bankInfoLb setTitle:dic[@"desCardName"] forState:UIControlStateNormal];
        [weakSelf dismissBankList];
    };
    
    self.banklist.addCard = ^{
        
        if (weakSelf.addCard) {
            
            [weakSelf dismissBankList];
            [weakSelf removeFromSuperview];
            weakSelf.addCard();
        }
    };
    
    [self.bankListView addSubview:self.banklist];
    [self.banklist mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(60);
        make.left.bottom.right.equalTo(0);
    }];
}
- (void)show
{
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    [window addSubview:self];
    
    [self mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.edges.equalTo(self.superview);
    }];
}

- (IBAction)bankClick:(id)sender {
    
    [self.bankListView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.payDetailView.right).offset(-kScreenWidth);
    }];
    
    [UIView animateWithDuration:0.5 animations:^{
       
        [self layoutIfNeeded];
    }];
}
- (IBAction)payClick:(id)sender {
    
    if (self.payClick) {
        
        [self removeFromSuperview];
        self.payClick();
    }
}


- (IBAction)dismiss:(id)sender {
    [self removeFromSuperview];
}
- (IBAction)back:(id)sender {
    
    [self dismissBankList];
}

- (void)dismissBankList
{
    [self.bankListView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.payDetailView.right).offset(0);
    }];
    [UIView animateWithDuration:0.5 animations:^{
        
        [self layoutIfNeeded];
    }];
}

@end
